package com.suneast.suneaststore.modules.search.adapter;

import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.CheckBox;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suneast.suneaststore.R;
import com.suneast.suneaststore.bean.search.SearchFilterBean;

public class SearchFilterAdapter extends BaseQuickAdapter<SearchFilterBean, BaseViewHolder> {

    public SearchFilterAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, SearchFilterBean item) {
        CheckBox showAllCb = helper.getView(R.id.cb_show_all);
        showAllCb.setVisibility(item.isShowTextAll() ? View.VISIBLE : View.GONE);
        showAllCb.setChecked(item.isShowingAll());
        helper.setText(R.id.tv_filter_title, item.getTitle());
        RecyclerView itemRV = helper.getView(R.id.rv_filter_items);
        itemRV.setLayoutManager(
                new GridLayoutManager(
                        helper.itemView.getContext(),
                        3,
                        GridLayoutManager.VERTICAL,
                        false));
        SearchFilterItemAdapter itemAdapter =
                new SearchFilterItemAdapter(R.layout.item_searech_filter_item, item.getItemList(), item.getTitle());
        itemRV.setAdapter(itemAdapter);
        helper.addOnClickListener(R.id.cb_show_all);
    }

}
